package com.common.domain.pojo;

import lombok.Data;

@Data
public class Result<T> {
    private int code;       // 状态码
    private String message; // 消息
    private T data;         // 数据

    public static final Integer SUCCESS = 200;
    public static final Integer ERROR = 500;

    // 私有构造方法，防止外部直接实例化
    private Result(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    // 成功响应，不带数据
    public static <T> Result<T> success() {
        return new Result<>(200, "Success", null);
    }

    // 成功响应，带数据
    public static <T> Result<T> success(T data) {
        return new Result<>(200, "Success", data);
    }

    // 失败响应，带消息
    public static <T> Result<T> error(String message) {
        return new Result<>(500, message, null);
    }

    // 失败响应，带状态码和消息
    public static <T> Result<T> error(int code, String message) {
        return new Result<>(code, message, null);
    }

    // 未认证
    public static <T> Result<T> unauthorized(String message) {
        return new Result<>(401, message, null);
    }
}

